<?php

/**
 * @Project NUKEVIET 3.0
 * @Author VINADES.,JSC (contact@vinades.vn)
 * @Copyright (C) 2010 VINADES., JSC. All rights reserved
 * @Createdate 3/9/2010 23:25
 */

if ( ! defined( 'NV_MAINFILE' ) ) die( 'Stop!!!' );

if ( ! nv_function_exists( 'nv_news_block_vip' ) )
{
    function nv_news_block_vip ( $block_config )
    {
        global $module_array_cat, $module_info, $site_mods,$my_head;
        $module = $block_config['module'];
        $sql = "SELECT id, catid, title, alias, hometext, homeimgfile, homeimgthumb, homeimgalt FROM `" . NV_PREFIXLANG . "_" . $site_mods[$module]['module_data'] . "_rows` WHERE status= 1 AND inhome='1' ORDER BY addtime ASC LIMIT 0 , 8";
        $list = nv_db_cache( $sql, 'id', $module );
        $i = 1;
        if ( ! empty( $list ) )
        {
            if ( file_exists( NV_ROOTDIR . "/themes/" . $module_info['template'] . "/modules/news/block_block_vip.tpl" ) )
            {
                $block_theme = $module_info['template'];
            }
            else
            {
                $block_theme = "default";
            }
			$my_head .= "<link type=\"text/css\" rel=\"Stylesheet\" href=\"" . NV_BASE_SITEURL . "themes/" . $block_theme . "/css/news_vip.css\" />\n";
			$my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "themes/" . $block_theme . "/js/news_vip/jquery.wt-rotator.min.js\"></script>\n";
			$my_head .= "<script type=\"text/javascript\" src=\"" . NV_BASE_SITEURL . "themes/" . $block_theme . "/js/news_vip/preview.js\"></script>\n";
            $xtpl = new XTemplate( "block_block_vip.tpl", NV_ROOTDIR . "/themes/" . $block_theme . "/modules/news" );
        	foreach ( $list as $l )
            {
                $link = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module . "&amp;" . NV_OP_VARIABLE . "=" . $module_array_cat[$l['catid']]['alias'] . "/" . $l['alias'] . "-" . $l['id'];
                $l['link'] = $link;
               if($l['homeimgfile']!="" and $l['homeimgthumb']!="") {
					$l['thumb'] = NV_BASE_SITEURL . NV_UPLOADS_DIR . '/' . $module . '/' . $l ['homeimgfile'];
				}elseif($l['homeimgfile']!="" and $l['homeimgthumb']=="") {
					$l['thumb'] = $l ['homeimgfile'];
				}else{
					$l['thumb']=NV_BASE_SITEURL . "themes/" . $block_theme . "/images/news_vip/noimages.jpg";
				}
				$l['hometext'] = nv_clean60( $l['hometext'], 200 );
                $xtpl->assign( 'ROW', $l );
                if ( ! empty( $l['thumb'] ) ) $xtpl->parse( 'main.loop.img' );
                $xtpl->assign( 'bg', ( ++ $i % 2 ) ? "bg" : "" );

                $xtpl->parse( 'main.loop' );
            }

            $xtpl->parse( 'main' );
            return $xtpl->text( 'main' );
        }
    }
}

if ( defined( 'NV_SYSTEM' ) )
{
    global $site_mods, $module_name, $global_array_cat, $module_array_cat;
    $module = $block_config['module'];
    if ( isset( $site_mods[$module] ) )
    {
        if ( $module == $module_name )
        {
            $module_array_cat = $global_array_cat;
            unset( $module_array_cat[0] );
        }
        else
        {
            $module_array_cat = array();
            $sql = "SELECT catid, parentid, title, alias, viewcat, subcatid, numlinks, description, inhome, keywords, who_view, groups_view FROM `" . NV_PREFIXLANG . "_" . $site_mods[$module]['module_data'] . "_cat` ORDER BY `order` ASC";
            $list = nv_db_cache( $sql, 'catid', $module );
            foreach ( $list as $l )
            {
                $module_array_cat[$l['catid']] = $l;
                $module_array_cat[$l['catid']]['link'] = NV_BASE_SITEURL . "index.php?" . NV_LANG_VARIABLE . "=" . NV_LANG_DATA . "&amp;" . NV_NAME_VARIABLE . "=" . $module . "&amp;" . NV_OP_VARIABLE . "=" . $l['alias'];
            }
        }
        $content = nv_news_block_vip( $block_config );
    }
}

?>